/**
 * 
 */
package myproject.main;

import java.util.Arrays;

import org.apache.log4j.Logger;

import myproject.api.ThreeD;

/**@version:
 * @Description: 相关公共计算方法
 * @author ：luokai
 * @date: date{2021年1月6日} 
 */
public class ArrayCount {
	private static final Logger log = Logger.getLogger(ArrayCount.class);
	
	/**
	*  计算和值
	**/
	public  int countSum(ThreeD threeD) {
		int sum=0;
		try {
			sum=threeD.getHundreds()+threeD.getTens()+threeD.getOnes();
			return sum;
		}  catch (Exception e) {
		e.printStackTrace();
	}
	return sum;
}	
	
	
	/**
	*  计算跨度
	**/
		  
	public  int countSpan(ThreeD threeD) {
		  	int max=0;
			try {
					//取差的绝对值	
				int a=Math.abs(threeD.getOnes()-threeD.getTens()); 
				int b=Math.abs(threeD.getOnes()-threeD.getHundreds());
				int c=Math.abs(threeD.getTens()-threeD.getHundreds());
				int temp = (a >= b) ? a : b;
				max = (temp >=c) ? temp : c;
				return max;
		
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return max;
	}	
		
	
	/**
	*  计算组选
	**/
	public  String countPacket(ThreeD threeD) {
		String packet="";
		try {
		int [] arr= {threeD.getHundreds(),threeD.getTens(),threeD.getOnes()};
		Arrays.sort(arr);
		for (int i : arr){
			packet += String.valueOf(i);
		 }
			log.info(packet);
		return packet;
	}  catch (Exception e) {
		e.printStackTrace();
	}
	return packet;
}	
	
	
	/**
	 *  判断形态
	 *  类型：开奖号码的类型，分以下三类：
	 *	[组三] 三个号码中有两个号码相同。
	 *	[组六] 三个号码均不相同。
	 *	[豹子] 三个号码相同。
	 **/
	  
	public  String countForm(ThreeD threeD) {
			String form="";
			try {
					if(threeD.getOnes()==threeD.getTens() 
							||threeD.getOnes()==threeD.getHundreds()
							||threeD.getTens()==threeD.getHundreds()) {
						if(threeD.getOnes()==threeD.getTens() && threeD.getOnes()==threeD.getHundreds()) {
							form="豹子";
							log.info(threeD.getResult()+" :豹子");
						}else {
							form="组三";
							log.info(threeD.getResult()+" :组三");
						}
					}else {
							form="组六";
							log.info(threeD.getResult()+" :组六");
					}
			
			}  catch (Exception e) {
				e.printStackTrace();
			}
			return form;
		}	  
		  
	/**
	 * 计算组三相同的数字 
	 **/
	  
	public int countArrayForm(ThreeD threeD) {
		int array = 0;
		try {
			array= threeD.getHundreds()==threeD.getTens()  ? threeD.getTens() : threeD.getOnes();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return array;
	}
	
	
	/**
	 * 计算组三除三余数
	 **/
	  
	public String countRemainder(ThreeD threeD) {
		String remainder = "000";
		try {
			int i=threeD.getHundreds()%3;
			int j=threeD.getTens()%3;
			int k=threeD.getOnes()%3;
			remainder=""+i+j+k;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return remainder;
	}
	
	/**
	*  计算大小
	**/
	
	public  String countSize(int threeD) {
		String size = "大";
		try {
			if(threeD<5) {
				size = "小";
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}
	/**
	*  计算奇偶
	**/
	public  String countOddEven(int threeD) {
		String oddeven = "奇";
		try {
			if(threeD%2 == 0) {
				oddeven = "偶";
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return oddeven;
	}
	/**
	*  计算质合
	**/
	public  String countPrimeOrComposite(int threeD) {
		String primeOrComposite = "质";
		try {
			if(threeD == 0 || threeD == 4 || threeD == 6 || threeD == 8 || threeD == 9 ) {
				primeOrComposite = "合";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return primeOrComposite;
	}
	/**
	*   计算升降序
	*   升序组合：指开奖号码百位到个位的号码顺序为从小到大。如123。
	*	降序组合：指开奖号码百位到个位的号码顺序为从大到小。如321。
	*	凹型组合：指开奖号码中，中间数值最小（即十位最小）。如312。
	*	凸型组合：指开奖号码中，中间数值最大（即十位最大）。如132。
	*	平型组合：指开奖号码三个数值一样(即豹子)。如111、222、333。
	*	扁型组合：指开奖号码中有两个数值一样(即组三)。如122、212、221。
	***/
	public  String countOrder(ThreeD threeD) {
		String order = "升";
		try {
			if(threeD.getForm().equals("组三")) {
				order = "扁";
			}
			else if(threeD.getForm().equals("豹子")){
				order = "平";
			}
			else {
				int i=0,j=0,k=0;
				i=threeD.getHundreds();
				j=threeD.getTens();
				k=threeD.getOnes();
				if(i<j && j<k) {
					order = "升";
				}
				else if(i>j && j>k) {
					order = "降";
				}
				else if(i>j && j<k) {
					order = "凹";
				}
				else if(i<j && j>k) {
					order = "凸";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return order;
	}
	/**
	 *  计算区间
	 *  号码区段：A代表数值在000-249之间,B代表数值在250-499之间,C代表数值在500-749之间,D代表数值在750-999之间。
	 **/
	public  String countInterval(ThreeD threeD) {
		String interval = "A";
		try {
			int i=Integer.valueOf(threeD.getResult());
			if(i<=249) {
				interval = "A";
			}
			else if(i<=499) {
				interval = "B";
			}
			else if(i<=749) {
				interval = "C";
			}
			else if(i<=999) {
				interval = "D";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return interval;
	}
	
	
	 public static void main(String []args) {
		

		 
	 }

}
